# -*- coding: utf-8 -*-

def shop_show(products):
        print('------商品列表------')
        for i in range(len(products)):
            print('{}\t{}\t{}'.format(i,products[i][0],products[i][1]), end='\t')
            print()


def shop_choice(products,shop_car,shop_cost):
    while True:
        nums = input('请选择您要购买的商品编号(q结束选择)>>>>')
        num = str(list(range(len(products))))
        if nums == 'q': break
        if  not num.count(nums):
            print('你选择的商品不在商品列表中，请重新选择')
            continue
        shop_car.append(products[int(nums)][0])
        shop_cost.append(products[int(nums)][1])


def list_print(shop_car,shop_cost):
    sum_b = 0
    print('您购买的商品清单:', end='\t')
    for a in range(len(shop_car)):
        print(shop_car[a], end='\t')

    print()

    print('您总共花费的金额:', end='\t')
    for b in range(len(shop_cost)):
        sum_b += int(shop_cost[b])
    print(sum_b, end='\t')

def main():
    products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 699]]
    shop_car = []
    shop_cost = []

    shop_show(products)
    shop_choice(products,shop_car,shop_cost)
    list_print(shop_car,shop_cost)


if __name__ == '__main__':
    main()
    # 大的毛病没有，有点小问题注意下：重复购买的后，最后q退出时，商品清单提示不是很优雅
